﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BussinessLogicLayer.BussinessObject;
using DataAccessLayer;

namespace BussinessLogicLayer.ChucNangQLDaoTao.CaiDat
{
    class CnQuanLyDaoTao : ICNQuanLyDaoTao
    {
        public NguoiQLDaoTao_DT LayThongTinNguoiQLDT(string mandt)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            NguoiQLDaoTao_DT ndt;
            ndt = tinChiEntities.QLDAOTAOs.Where(qldaotao => qldaotao.MaNV == mandt).Select(
                qldaotao => new NguoiQLDaoTao_DT
                {
                    ChucVu = qldaotao.Chucvu,
                    GioiTinh = qldaotao.Gioitinh.Value,
                    HoTen = qldaotao.Hoten,
                    MaNgQLyDaoTao = qldaotao.MaNV,
                    NgaySinh = qldaotao.Ngaysinh.Value,
                    QueQuan = qldaotao.Quequan
                })
                .First();
            return ndt;
        }

        #region Implementation of ILayDoiTuongDt

        public List<MauDiemBo> LayDsMauDiem()
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            List<MauDiemBo> ds;
            ds=tinChiEntities.MAUDIEMs.Select(maudiem => new MauDiemBo
                {
                    HeSoChuyenCan = maudiem.Hesochuyencan.Value,
                    HeSoCuoiKy = maudiem.Hesocuoiky.Value,
                    HeSoGiuaKy = maudiem.Hesocuoiky.Value,
                    MaMau = maudiem.MaMau
                }).ToList();
            return ds;
        }

        public List<LopHpBo> LayDsLopHp()
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            List<LopHpBo> ds;
            ds = tinChiEntities.LOPHPs.Select(lophp => new LopHpBo
                {
                    KhoaHoc = lophp.Khoahoc,
                    MaGv = lophp.MaGV,
                    MaHp = lophp.MaHP,
                    MaLopHp = lophp.MaLopHP,
                    MaMau = lophp.MaMau
                }).ToList();
            return ds;
        }

        public List<KhoaBo> LayDsKhoa()
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            List<KhoaBo> ds;
            ds = tinChiEntities.KHOAs.Select(khoa => new KhoaBo
                {
                    MaKhoa = khoa.MaKhoa,
                    TenKhoa = khoa.Tenkhoa
                }).ToList();
            return ds;
        }

        public List<string> LayDsMaKhoa()
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            List<string> ds;
            ds = tinChiEntities.KHOAs.Select(khoa => khoa.MaKhoa).ToList();
            return ds;
        }

        public List<HocPhanBo> LayDsMaHP()
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            List<HocPhanBo> ds;
            ds = tinChiEntities.HocPhans.Select(phan => new HocPhanBo
                {
                    MaHP = phan.MaHP,
                    TenHP = phan.TenHP
                }).ToList();
            return ds;
        }

        #endregion

        #region Implementation of IPhanCongHp

        public void PhanCongHpThem(LopPhanCongHpBo maKhoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            PHANCONGHOCPHAN pchp = new PHANCONGHOCPHAN
                {
                    MaKhoa = maKhoa.MaKhoa,
                    MaHP = maKhoa.MaHp,
                    MaPCHP = maKhoa.MaPhanCongHp
                };
            tinChiEntities.PHANCONGHOCPHANs.InsertOnSubmit(pchp);
            tinChiEntities.SubmitChanges();
        }

        public void PhanCongHpCapNhat(LopPhanCongHpBo maKhoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            PHANCONGHOCPHAN pchp = tinChiEntities.PHANCONGHOCPHANs.First(pc => pc.MaPCHP == maKhoa.MaPhanCongHp);
            pchp.MaKhoa = maKhoa.MaKhoa;
            pchp.MaHP = maKhoa.MaHp;
            pchp.MaPCHP = maKhoa.MaPhanCongHp;
            tinChiEntities.SubmitChanges();
        }

        public void PhanCongHpXoa(string maKhoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            PHANCONGHOCPHAN pchp = tinChiEntities.PHANCONGHOCPHANs.First(pc => pc.MaPCHP == maKhoa);
            tinChiEntities.PHANCONGHOCPHANs.DeleteOnSubmit(pchp);
            tinChiEntities.SubmitChanges();
        }

        #endregion

        #region Implementation of IQlyKhoa

        public void QlyKhoaThem(KhoaBo MaKhoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            KHOA khoa = new KHOA
                {
                    MaKhoa = MaKhoa.MaKhoa,
                    Tenkhoa = MaKhoa.TenKhoa
                };
            tinChiEntities.KHOAs.InsertOnSubmit(khoa);
            tinChiEntities.SubmitChanges();
        }

        public void QlyKhoaCapNhat(KhoaBo MaKhoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            KHOA khoa = tinChiEntities.KHOAs.First(khoa1 => khoa1.MaKhoa == MaKhoa.MaKhoa);
            khoa.Tenkhoa = MaKhoa.TenKhoa;
            tinChiEntities.SubmitChanges();
        }

        public void QlyKhoaXoa(string MaKhoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            KHOA khoa = tinChiEntities.KHOAs.First(khoa1 => khoa1.MaKhoa ==MaKhoa);
            tinChiEntities.KHOAs.DeleteOnSubmit(khoa);
            tinChiEntities.SubmitChanges();
        }

        #endregion

        #region Implementation of IQlyLopHp

        public void QlyLopHpThem(LopHpBo MaLop)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            LOPHP lophp = new LOPHP
                {
                    MaHP = MaLop.MaHp,
                    MaLopHP = MaLop.MaLopHp,
                    MaMau = MaLop.MaMau,
                    MaGV = MaLop.MaGv,
                    Khoahoc = MaLop.KhoaHoc
                };
            tinChiEntities.LOPHPs.InsertOnSubmit(lophp);
            tinChiEntities.SubmitChanges();
        }

        public void QlyLopHpCapNhat(LopHpBo MaLop)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            LOPHP first = tinChiEntities.LOPHPs.First(lophp => lophp.MaLopHP == MaLop.MaLopHp);
            first.MaHP = MaLop.MaHp;
            first.MaLopHP = MaLop.MaLopHp;
            first.MaMau = MaLop.MaMau;
            first.Khoahoc = MaLop.KhoaHoc;
            first.MaGV = MaLop.MaGv;
            tinChiEntities.SubmitChanges();
        }

        public void QlyLopHpXoa(string MaLop)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            LOPHP lophp1 = tinChiEntities.LOPHPs.First(lophp => lophp.MaLopHP == MaLop);
            tinChiEntities.LOPHPs.DeleteOnSubmit(lophp1);
            tinChiEntities.SubmitChanges();
        }

        #endregion

        #region Implementation of IQlyMauDiem

        public void QlyMauDiemThem(MauDiemBo MaMau)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            MAUDIEM maudm = new MAUDIEM
                {
                    MaMau = MaMau.MaMau,
                    Hesochuyencan = MaMau.HeSoChuyenCan,
                    Hesocuoiky = MaMau.HeSoCuoiKy,
                    Hesogiuaky = MaMau.HeSoGiuaKy
                };
            tinChiEntities.MAUDIEMs.InsertOnSubmit(maudm);
            tinChiEntities.SubmitChanges();
        }

        public void QlyMauDiemCapNhat(MauDiemBo MaMau)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            MAUDIEM maudm = tinChiEntities.MAUDIEMs.First(maudiem => maudiem.MaMau == MaMau.MaMau);
            maudm.Hesochuyencan = MaMau.HeSoChuyenCan;
            maudm.Hesocuoiky = MaMau.HeSoCuoiKy;
            maudm.Hesogiuaky = MaMau.HeSoGiuaKy;
            tinChiEntities.SubmitChanges();
        }

        public void QlyMauDiemXoa(string MaMau)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            MAUDIEM maudm = tinChiEntities.MAUDIEMs.First(maudiem => maudiem.MaMau == MaMau);
            tinChiEntities.MAUDIEMs.DeleteOnSubmit(maudm);
            tinChiEntities.SubmitChanges();
        }

        #endregion
    }
}
